package com.dxysun.gateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dxysun.gateway.service.DynamicRouteService;

import reactor.core.publisher.Flux;

/**
 * @author dongxiyan
 * @date 2020/2/14 20:31
 */
@RestController
public class MainController
{

    @Autowired
    DynamicRouteService dynamicRouteService;

    @Autowired private RouteDefinitionLocator routeDefinitionLocator;

    //获取网关所有的路由信息
    @RequestMapping("/routes")
    public Flux<RouteDefinition> getRouteDefinitions(){
        return routeDefinitionLocator.getRouteDefinitions();
    }

    @RequestMapping("/index")
    public String index()
    {
        return "gateway index";
    }

    @RequestMapping("/refresh")
    public String refresh()
    {
        dynamicRouteService.update(dynamicRouteService.data());
        return "refresh";
    }
}
